package ch.kerbtier.malurus.coreimpl;

import java.io.Serializable;

import ch.kerbtier.malurus.Visitor;
import ch.kerbtier.malurus.Component;

public class CiComponent implements Component, Serializable {

	private CiMalurusInstance instance;
	private CiCompositeComponent parent;
	private String id;
	private boolean visible = true;
	private boolean modified = false;
	private String realisation;

	public String getId() {
		return id;
	}

	protected void setId(String id) {
		this.id = id;
	}

	public CiCompositeComponent getParent() {
		return parent;
	}

	public boolean modified() {
		return modified;
	}

	public CiMalurusInstance getInstance() {
		return instance;
	}

	protected void setParent(CiCompositeComponent parent) {
		this.parent = parent;
	}

	protected void setInstance(CiMalurusInstance instance) {
		this.instance = instance;
	}

	public boolean isVisible() {
		return visible;
	}

	public void setVisible(boolean visible) {
		if(this.visible != visible){
			this.visible = visible;
			if(parent != null){
				parent.setChangedStructure(true);
			}
		}
	}

	public void acceptVisitor(Visitor visitor) {
		visitor.visit(this);
	}

	public void setModified(boolean modified) {
		this.modified = modified;
	}

	public String getClientId() {
		if(parent != null){
			return parent.getClientId() + "." + id;
		}
		return id;
	}
	
	@Override
	public String toString(){
		return "[Component:" + getClientId() + "]";
	}

	public String getRealisation() {
		return realisation;
	}

	public void setRealisation(String realisation) {
		this.realisation = realisation;
	}
}
